using JKFrame;
using System.Collections;
using UnityEditor.PackageManager;
using UnityEngine;

//Host
public partial class GameSceneManager : MonoBehaviour
{

    void ServerInit()
    {
        AOIManager.Instance.Init();
        ClientsManager.Instance.Init();
        MapManager.Instance.HostInit();

    }
}


//Common
public partial class GameSceneManager : MonoBehaviour
{

    void Start()
    {
        MapManager.Instance.ClientInit();
        PlayerManager.Instance.Init();
        StartCoroutine(LoadGame());
        UISystem.Close<UI_MainMenuWindow>();
        if (NetManager.Instance.IsHost)
        {
            ServerInit();

            ClientsManager.Instance.AddClient(NetManager.ServerClientId,ClientState.Gaming);
            ClientsManager.Instance.CreatePlayer(NetManager.ServerClientId);

        }
    }

    private IEnumerator LoadGame()
    {
        //UI_LoadingWindow loadingWindow = UISystem.Show<UI_LoadingWindow>();
        //loadingWindow.Set("Loading...");
        //// 申请进入游戏
        //NetMessageManager.Instance.SendMessageToServer(MessageType.C_S_EnterGame, default(C_S_EnterGame));
        //float progress = 0;
        //loadingWindow.UpdateProgress(progress, 100);
        //yield return CoroutineTool.WaitForFrame();
        //while (!ClientMapManager.Instance.IsLoadingCompleted())
        //{
        //    yield return CoroutineTool.WaitForFrame();
        //    if (progress < 99)
        //    {
        //        progress += 0.1f;
        //        loadingWindow.UpdateProgress(progress, 100);
        //    }
        //}
        //progress = 99;
        //loadingWindow.UpdateProgress(progress, 100);
        //while (!PlayerManager.Instance.IsLoadingCompleted())
        //{
        //    yield return CoroutineTool.WaitForFrame();
        //}
        //progress = 100;
        //loadingWindow.UpdateProgress(progress, 100);
        //UISystem.Close<UI_LoadingWindow>();
        //UISystem.Show<UI_ChatWindow>();


        yield return null;
    }
}
